<?php

use think\facade\Route;
use think\facade\Request;

$version = Request::header('version', 'v1');#接口版本
Route::group('', function () use ($version) {

    /**
     * 会员管理
     */
    Route::group('member', function () use ($version) {
        Route::get('get-info', "api/{$version}.Member/getInfo");
    })->middleware('checkLogin');


    Route::group('index', function () use ($version) {
        Route::get('get-info', "api/{$version}.Index/index");    //首页接口
        Route::get('index_search', "api/{$version}.Index/search");  //首页搜索
        Route::get('get-banner', "api/{$version}.Index/banner");
    });

    Route::group('article', function () use ($version) {
        Route::get('get-info', "api/{$version}.Article/article");    //获取文章列表
        Route::get('content', "api/{$version}.Article/content");    //获取文章详情
    });

    Route::group('sucai', function () use ($version) {
        Route::get('get-info', "api/{$version}.Sucai/caseindex");    //获取素材库
        Route::get('caselist', "api/{$version}.Sucai/caselist");    //获取素材列表
        Route::get('content', "api/{$version}.Sucai/content");    //获取素材详情
    });

    Route::group('wenda', function () use ($version) {
        Route::get('get-info', "api/{$version}.Wenda/wendalist");    ///获取问答列表
        Route::get('search', "api/{$version}.Wenda/search");    //问答搜索
        Route::get('content', "api/{$version}.Wenda/content");    //问答详情
    });
    //实例
    Route::group('cases', function () use ($version) {
        Route::get('index', "api/{$version}.Cases/index"); //实例首页
        Route::get('case-list', "api/{$version}.Cases/caselist");//获取实例列表
        Route::get('content', "api/{$version}.Cases/content");//获取实例详情
    });

    Route::group('login', function () use ($version) {
        Route::get('create-code', "api/{$version}.Login/createcode"); //实例首页
        Route::get('reg', "api/{$version}.Login/reg");//获取实例列表
        Route::get('content', "api/{$version}.Cases/content");//获取实例详情
    });
})->allowCrossDomain([
    'Access-Control-Allow-Origin' => '*',
    'Access-Control-Allow-Methods' => 'GET,POST',
    'Access-Control-Allow-Headers' => 'content-type,token,version',
    'Access-Control-Allow-Credentials' => 'true'
]);

//第二版
$versions = Request::header('versions', 'v2');#接口版本
Route::group('', function () use ($versions) {

    /**
     * 登录
     * 注册
     */
    Route::group('site', function () use ($versions) {
        Route::post('login', "api/{$versions}.Site/login");
        Route::post('reg', "api/{$versions}.Site/register");
        Route::get('verify',"api/{$versions}.Code/verify");
        Route::get('check',"api/{$versions}.Code/check");
        Route::get('delcache',"api/{$versions}.Code/delCache");
    });

    /**
     * 个人中心
     */
    Route::group('personal', function () use ($versions) {
        Route::get('index', "api/{$versions}.personal/index");//获取个人信息
        Route::post('edit', "api/{$versions}.personal/editper");//修改个人信息
        Route::post('upload', "api/{$versions}.personal/upload");//修改个人头像
        Route::post('sub', "api/{$versions}.personal/subproblem");//提交问题
        Route::get('problems', "api/{$versions}.personal/problems");//已提交问题
        Route::get('tongzhi', "api/{$versions}.personal/tongzhi");//系统通知
        Route::get('example', "api/{$versions}.down/example");//我的下载-实例
        Route::get('sucai', "api/{$versions}.down/sucai");//我的下载-素材
        Route::get('example_del', "api/{$versions}.down/example_del");//我的下载-实例
        Route::get('sucai_del', "api/{$versions}.down/sucai_del");//我的下载-素材
        Route::get('cate', "api/{$versions}.personal/cate");//文章，问答发布分类-素材
        Route::post('reaarticle', "api/{$versions}.personal/reaarticle");//发布文章
        Route::get('article', "api/{$versions}.personal/article");//我的发布文章
        Route::post('reaquestion', "api/{$versions}.personal/reaquestion");//发布文章
        Route::get('question', "api/{$versions}.personal/question");//我的发布问答
        Route::delete('delarticle', "api/{$versions}.personal/delarticle");//删除我的发布文章
        Route::delete('delquestion', "api/{$versions}.personal/delquestion");//删除我的发布问答
    })->middleware('checkLogin');

    /**
     * 我的收藏
     */
    Route::group('collection', function () use ($versions) {
        Route::get('index', "api/{$versions}.Collection/index");
    })->middleware('checkLogin');

    /**
     * 下载
     */
    Route::group('down', function () use ($versions) {
        Route::get('down', "api/{$versions}.down/down");
        Route::get('example_down', "api/{$versions}.down/example_down");
    })->middleware('checkLogin');



    //导航，网站底部信息
    Route::group('nav', function () use ($versions) {
        Route::get('index', "api/{$versions}.nav/index");
    });
    //首页
    Route::group('index', function () use ($versions) {
        Route::get('index', "api/{$versions}.index/index");
        Route::get('questions', "api/{$versions}.index/questions");
        Route::get('details', "api/{$versions}.index/details");
    });
    //素材
    Route::group('sucai', function () use ($versions) {
        Route::get('index', "api/{$versions}.sucai/index");
        Route::get('down', "api/{$versions}.down/picture_down");
        Route::get('sucai', "api/{$versions}.sucai/sucai");
    });

    //文章
    Route::group('article', function () use ($versions) {
        Route::get('index', "api/{$versions}.article/index");
        Route::get('wenzhang', "api/{$versions}.article/wenzhang");

        Route::get('list', "api/{$versions}.article/list");//评论列表
    });
    Route::group('article', function () use ($versions) {
        //个人评论
        Route::post('pinglun', "api/{$versions}.article/pinglun");
    })->middleware('checkLogin');


    //问答
    Route::group('question', function () use ($versions) {
        Route::get('index', "api/{$versions}.question/index");
        Route::get('wenda', "api/{$versions}.question/wenda");
        Route::get('list', "api/{$versions}.question/list");//评论列表
    });
    Route::group('question', function () use ($versions) {
        //个人评论
        Route::post('pinglun', "api/{$versions}.question/pinglun");
    })->middleware('checkLogin');

    //技术社区
    Route::group('technology', function () use ($versions) {
        Route::get('index', "api/{$versions}.technology/index");
        Route::get('jishe', "api/{$versions}.technology/jishe");
        Route::get('list', "api/{$versions}.technology/list");//评论列表
    });
    Route::group('technology', function () use ($versions) {
        //个人评论
        Route::post('pinglun', "api/{$versions}.technology/pinglun");
    })->middleware('checkLogin');

    //实例
    Route::group('example', function () use ($versions) {
        Route::get('index', "api/{$versions}.Example/index"); //实例
        Route::get('cates', "api/{$versions}.Example/cates"); //实例小分类
        Route::get('list', "api/{$versions}.Example/list"); //实例小分类
        Route::get('cate1', "api/{$versions}.Example/cate1"); //实例图标
    });
    Route::group('example', function () use ($versions) {
        Route::get('content', "api/{$versions}.Example/content"); //实例详情
        Route::get('down', "api/{$versions}.Down/example_down"); //下载实例存记录表
        Route::get('zan', "api/{$versions}.Example/zan"); //实例点赞
        Route::get('col', "api/{$versions}.Example/col"); //实例收藏
    })->middleware('checkLogin');

    Route::group('article', function () use ($versions) {
        Route::get('details', "api/{$versions}.article/details");
        Route::get('zan', "api/{$versions}.Article/zan"); //文章点赞
        Route::get('col', "api/{$versions}.Article/col"); //文章收藏
    })->middleware('checkLogin');

    Route::group('question', function () use ($versions) {
        Route::get('details', "api/{$versions}.question/details");
        Route::get('zan', "api/{$versions}.Question/zan"); //问答点赞
        Route::get('col', "api/{$versions}.Question/col"); //问答收藏
    })->middleware('checkLogin');

    Route::group('technology', function () use ($versions) {
        Route::get('details', "api/{$versions}.technology/details");
        Route::get('zan', "api/{$versions}.Technology/zan"); //技术社区点赞
        Route::get('col', "api/{$versions}.Technology/col"); //技术社区收藏
    })->middleware('checkLogin');

    Route::group('sucai', function () use ($versions) {
        Route::get('details', "api/{$versions}.sucai/details");
        Route::get('col', "api/{$versions}.Sucai/col"); //素材库收藏
    })->middleware('checkLogin');

    Route::group('search', function () use ($versions) {
        Route::get('index', "api/{$versions}.search/index"); //搜索
    });

})->allowCrossDomain([
    'Access-Control-Allow-Origin' => '*',
    'Access-Control-Allow-Methods' => 'GET,POST,DELETE',
    'Access-Control-Allow-Headers' => 'token,version,Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With',
    'Access-Control-Allow-CredContent-Typeentials' => 'true',
]);